package fr.mma.socle.dao;

import java.util.ArrayList;
import java.util.List;

import com.googlecode.objectify.util.DAOBase;

public class CommonDao<T>  extends DAOBase{

	private final Class<T> parameterClass;
	
	/**
	 * Constructeur.
	 * @param parameterClass
	 */
	public CommonDao(final Class<T> parameterClass) {
		super();
		this.parameterClass = parameterClass;
	}
	
    public List<T> getAll() {
    	final List<T>allT = new ArrayList<T>();
		for (T t : ofy().query(parameterClass)) {
			allT.add(t);
		} 
		return allT;
    }
    

	public void save(final T type) {
		ofy().put(type);
	}
	
	public void delete(final T type) {
		ofy().delete(type);
	}
	
	public void delete(final String id) {
		ofy().delete(parameterClass, id);
	}
	
	public void delete(final long id) {
		ofy().delete(parameterClass, id);
	}
}
